package Partition;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-02-20
 * Time:14:32
 * Text：归并排序
 */
public class Text5 {
    int[] tmp;

    // 归并方法
    public int[] sortArray(int[] nums) {
        tmp=new int[nums.length];
        qsort(nums,0,nums.length-1);
        return nums;
    }
    public void qsort(int[] nums,int l,int r){
        if(l>=r)
            return ;
        int mid=(l+r)/2;
        qsort(nums,l,mid);
        qsort(nums,mid+1,r);

        //分成2部分，进行排序
        int cur1=l,cur2=mid+1,i=0;
        while(cur1<=mid && cur2<=r){
            tmp[i++]=nums[cur1]>=nums[cur2]?nums[cur2++]:nums[cur1++];
        }
        while(cur1<=mid) tmp[i++]=nums[cur1++];
        while(cur2<=r) tmp[i++]=nums[cur2++];
        for(int j=l;j<=r;j++){
            nums[j]=tmp[j-l];
        }
    }

    public static void main(String[] args) {

    }
}
